import React,{Component} from 'react';
import {Icon,Button} from 'antd';
import {Redirect} from 'react-router-dom';
import axios from 'axios';
import './shoppingcart.scss';

class ShoppingCart extends Component{
    constructor(){
        super();
        this.state = {
            tokenType:1
        }
    }
    //对于是否已经登录的判断我们放在componentWillMount
	componentDidMount(){
		//token的验证
		axios({
			method:'get',
			url:'http://192.168.2.251:7001/center',
			headers:{
				'Authorization':localStorage['token']
			}
		}).then((res)=>{
			// console.log(res);
			if(res.data.code === 0){//登录状态获取成功
				this.setState({
					tokenType:true
				})
			}else{
				//this.props.history.push('/login');
				this.setState({
					tokenType:false
				})
			}
			// console.log(this.state.tokenType);
		})
		
		
	}
    backFunccenter=()=>{
        this.props.history.push('/')
    }

    componentWillUnmount(){
		this.setState = (state,callback)=>{
			return;
		}
    }
    goMainFunc=()=>{
        this.props.history.push('/')
    }
    render(){
        if(this.state.tokenType){
            return (
                <div id='ShoppingCart'>               
                    <div className='ShoppingCart_top'><div className="div1" onClick={this.backFunccenter}><Icon type="left" className="leftBack" /></div><div className="div2">购物车</div></div>
                    <div className='ShoppingCart_content'> 
                        <div className='content1'></div>
                        <div className='content2'><Button type='primary' className='content2_but' onClick={this.goMainFunc}>去首页逛逛</Button></div>
                    </div>
                </div>
            )
        }else{
            return <Redirect to='/lognin' />
        }
    }
}

export default ShoppingCart;